package com.sanjiahantang.youjiarole.module.me.order.views.impl;

import android.view.View;
import android.widget.TextView;

import com.sanjiahantang.youjiarole.R;
import com.sanjiahantang.youjiarole.base.BaseMvpActivity;
import com.sanjiahantang.youjiarole.base.BaseView;
import com.sanjiahantang.youjiarole.module.me.order.beans.RequireOrderBean;
import com.sanjiahantang.youjiarole.module.me.order.presenters.OrderPresenter;
import com.sanjiahantang.youjiarole.module.me.order.views.OrderView;

/**
 * Created by zy on 2017/10/24.
 */

public class OrderConfirmActivity extends BaseMvpActivity<OrderView,OrderPresenter> implements OrderView, View.OnClickListener {


    private int id;
    private TextView txtPrice,txtTotal;
    @Override
    public void showProgress() {
        super.showProgress($this);
    }

    @Override
    public OrderPresenter initPresenter() {
        return new OrderPresenter();
    }

    @Override
    public void initView() {
        setContentView(R.layout.activity_require_order);
        id = getIntent().getIntExtra(KEY_ID,0);
        TextView title = (TextView) findViewById(R.id.title);
        title.setText("确认订单");
        findViewById(R.id.fl_Left).setOnClickListener(this);
        txtPrice = (TextView) findViewById(R.id.txtPrice);
        txtTotal = (TextView) findViewById(R.id.txtTotal);
    }

    @Override
    public void initData() {
        presenter.getRequireOrderPrice($this, id, new BaseView.OnLoadListener() {
            @Override
            public void onLoad(Object content) {
                if (content instanceof RequireOrderBean.Data){
                    RequireOrderBean.Data data = (RequireOrderBean.Data) content;
                    double price = Double.parseDouble(data.getServicePrice());
                    int num = data.getServiceNum();
                    txtPrice.setText(String.format("%.2f",price * num));
                    txtTotal.setText(String.format("%.2f",price * num));
                }

            }
        });
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.fl_Left:
                finish();
                break;
        }
    }
}
